﻿var mobile = "";
$(function () {

    if (sessionStorage.getItem("isgroup") == "0") {

         $("#add").hide();
        //  $("#fs").hide();
        //
        // $("#delsb").hide();
    }
    if (sessionStorage.getItem("type") == "3") {
        $("#fs").hide();
    }
    $("#add").click(function (z) {
        // $("#user_name").attr("disabled",false);
        // $("#myModal").find("span").empty();      $("#myModal").find("input").val("");
        // $("#myModalLabel").text("新增");
        //mobile="";

        console.log(123);
        parent.addTabs({id:'101',title: '添加节目',close: true,url: '?#/page/Program/addtow'});
        // location.href="?#/page/Program/add";

    });
    //appvm.prompt();
    // domain.jsonthis.modify();
});


$(document).ready(function () {
    $.jgrid.defaults.styleUI = "Bootstrap";
    $("#table_list_1").jqGrid({
        data: [],
        datatype: "local",
        height: "100%",
        autowidth: true,
        shrinkToFit: true,
        rowNum: 20,
        rowList: [10, 20, 30, 60, 90, 100, 200, 500],
        //colNames: ["编号", "名称", "手机号码"],
        colModel: [{
            name: 'programid', index: 'programid', align: "center", width: 25, label: "编号", align: 'center',
        },
        {
            name: 'company_id', index: 'company_id', align: "center", width: 25, label: "company_id", align: 'center', hidden: true,


        },

        {
            name: 'group_programid', index: 'group_programid', align: "center", width: 20, label: "节目号", align: 'center',
            formatter: function (value, options, row) {

                return parseInt(value) + 1;
            }
        },
        {
            name: 'festivalname', index: 'festivalname', align: "center", width: 34, label: "节目名称", align: 'center',
        },
        {
            name: 'type', index: 'type', align: "center", width: 23, label: "节目类型", align: 'center',

            formatter: function (value, options, row) {

                if (value == "0") {


                    return "公益广告";

                }

                if (value == "1") {

                    return "商业广告";
                }

                if (value == "2") {

                    return "即时节目";
                }

                if (value == "3") {

                    return "简短固定广告";
                }

            }

        },
        {
            name: 'devicetype', index: 'devicetype', align: "center", width: 18, label: "设备类型", align: 'center',
            formatter: function (value, options, row) {

                if (value == "0") {


                    return "单色";

                }

                if (value == "1") {

                    return "双色";
                }

                if (value == "2") {

                    return "全彩";
                }

                if (value == "3") {

                    return "安卓";
                }
                return "";
            }
        },

        {
            name: 'starttime', index: 'starttime', align: "center", width: 25, label: "播放开始日期", align: 'center',
            formatter: function (value, options, row) {

                if (typeof (value) != "undefined") {
                    try {
                        var date = new Date(value)

                        return date.Format("yyyy-MM-dd");
                    } catch (ex) {

                        console.log(ex);
                    }
                }
                return "";
            }
        },
        {
            name: 'endtime', index: 'endtime', align: "center", width: 25, label: "播放结束日期", align: 'center',
            formatter: function (value, options, row) {

                if (typeof (value) != "undefined") {
                    try {
                        var date = new Date(value)

                        return date.Format("yyyy-MM-dd");
                    } catch (ex) {

                        console.log(ex);
                    }
                }
                return "";
            }
        },
        // {
        //   name: 'order_serialno', index: 'order_serialno',align:"center", width: 30, label: "订单号", align: 'center',
        // },
        {
            name: 'zeroindex', index: 'zeroindex', align: "center", width: 18, label: "分区数量", align: 'center',
        },
        {
            name: 'create_time', index: 'create_time', align: "center", width: 35, label: "时间", align: 'center',
            formatter: function (value, options, row) {

                if (typeof (value) != "undefined") {
                    try {
                        var date = new Date(value)

                        return date.Format("yyyy-MM-dd hh:mm:ss");
                    } catch (ex) {

                        console.log(ex);
                    }
                }
                return "";
            },
        },
        {
            name: 'permissions', index: 'permissions', width: 18, align: "center", label: "审核状态", align: 'center',
            formatter: function (value, options, row) {
                //console.log(options.rowId);
                var html = "";
                if (parseInt(value) == 1) {

                    html = "<input type='hidden' class='permissions' value='" + value + "'><a style='color:green' data-target='#modalExamine'  data-toggle='modal' onclick=queryExamine('" + row.programid + "')>通过</a>";

                }
                if (parseInt(value) == 2) {
                    html = "<input type='hidden' class='permissions'value='" + value + "'><span style='color:blue'>未审核</span>";
                }
                if (parseInt(value) == 3) {
                    html = "<input type='hidden' class='permissions' value='" + value + "'><a style='color:red' data-target='#modalExamine'  data-toggle='modal' onclick=queryExamine('" + row.programid + "')>打回</a>";
                } if (parseInt(value) == 4) {
                    html = "<input type='hidden' class='permissions' value='" + value + "'><a style='color:red' data-target='#modalExamine'  data-toggle='modal' onclick=queryExamine('" + row.programid + "')>拒绝</a>";
                }

                return html;
            }
        },
        {
            name: '', index: '', width: 17, align: "center", label: "设备状态", align: 'center',
            formatter: function (value, options, row) {
                //console.log(options.rowId);
                var html = "<a onclick=state('" + row.programid + "','" + row.devicetype + "');>查看</a>";
                return html;
            }
        },
        {
            name: 'cz', index: 'cz', width: 25, align: "center", label: "操作", align: 'center',
            formatter: function (value, options, row) {

                var html = "<button type='button'  class='btn btn-primary' onclick=modify('" + row.programid + "','" + row.group_programid + "');>修改</button>";

                return html;
            }
        },
        ],
        pager: "#pager_list_1",
        viewrecords: true,
        multiselect: true,
        caption: "节目列表",
        hidegrid: false,
        ondblClickRow: function (row) {
            //双击一行触发的事件
            var rowDate=$("#table_list_1").jqGrid('getRowData', row);
            $("#update").click();
           
           console.log("节目编号"+rowDate.programid)
           modify(rowDate.programid,parseInt(rowDate.group_programid)-1);
           
        },

        onPaging: function (pageBtn) {
            console.log(":" + pageBtn);
            //	    	var re_records = $jqgrid.getGridParam('records');//获取返回的记录数  
            var re_page = $("#table_list_1").getGridParam('page');//获取返回的当前页
            var re_rowNum = $("#table_list_1").getGridParam('rowNum');//获取每页数
            var re_total = $("#table_list_1").getGridParam('lastpage');//获取总页数
            //alert(re_total);

            if (pageBtn === "next") {
                // initJqgrid(re_page+1,re_rowNum);
                // if()
                pageval = pageval + 1;
                cxlist();
            }
            if (pageBtn === "prev") {

                pageval = pageval - 1; cxlist();
            }

            if (pageBtn == "last") {

                pageval = re_total;

                cxlist();

            }
            if (pageBtn == "first") {

                pageval = 1;

                cxlist();

            }

            if (pageBtn == "records") {

                sizeval = $(".ui-pg-selbox").val();
                pageval = 1;
                cxlist();
            }
        },
        // onSelectAll : function (rowids,status) {
        //     doSelect(rowids,status);
        // }, m
        
         
      
    });

    $("#table_list_1").setGridHeight($(window).height() * 0.73);

    $(window).resize(function () {
        $("#table_list_1").setGridWidth($(window).width()); $("#table_list_1").setGridHeight($(window).height() * 0.73);
    });
    for(var i=1;i<=225;i++){

        $("#playcount").append("<option value='"+i+"'>"+i+"</option>");
        }
});
var sizeval = 20;
var pageval = 1;
var usernameval = $("#usnameval").val();
var conameval = "";
var json = "";


//节目不通过就不选中
// function doSelect(rowids,status) {
   
   
    
//     var allJQGridData = $('#table_list_1').jqGrid('getGridParam', 'data');
//     var ro="";
//     for (i = 1; i <= allJQGridData.length; i++) {      
//         ro = $("#table_list_1 #" + i + " .permissions").val();            
//         if (ro!=1){
            
//             $("#table_list_1").jqGrid('setSelection', i, true);  //无法选中
//         }
// }

// }


window.cxlist = function () {

    domain.ajaxUrl({
        method: 'POST',
        url: domain.testUrl + "/Threeinjection/programManagement/queryProgramInfolist",
        data: { size: sizeval, page: pageval, coid: sessionStorage.getItem("coid"),
               festivalname: $("#usnameval").val(), type: $("#type").val(),"audit":$("#examresult").val(), devicetype: $("#devicetype").val(),sessionid: sessionStorage.getItem("sid") },
        // datatype:"JSON",
        success: function (response) {

            // console.log(response);

            json = response;
            var data = JSON.parse(response);
            var reader = {
                root: function (obj) { return data.rows; },
                page: function (obj) { return pageval; },
                total: function (obj) { return data.taotal; },
                records: function (obj) {

                    return data.records;
                },

            };
            $("#table_list_1").setGridParam({ data: data.rows, localReader: reader }).trigger('reloadGrid');
            var re_records =data.rows;
         
            if(re_records==""||re_records==null){
                 if($(".norecords").html() == null){
                    $("#table_list_1").parent().append("<div class=\"norecords\">没有符合数据</div>");
                 }
                 $(".norecords").show();
            }else{

                $(".norecords").hide();
            }
            //隐藏修改
            if(sessionStorage.getItem("isgroup")=="0"){
            $("#table_list_1").hideCol("cz");
            $("#table_list_1").setGridWidth($(window).width());
            }
           
            var rowData = $('#table_list_1').jqGrid("getRowData");//所有行，数组

            var ro = "";
            var tab="";
            for (var i = 0; i < rowData.length; i++) {
                var ii=i+1;
                tab=$("#table_list_1 #" + ii);
                ro = $("#table_list_1 #" + ii + " .permissions").val();
                if (parseInt(ro)!= 1) {

                    tab.css("background-color", "rgba(126, 128, 9, 0.1)");
                    //隐藏复选框
                    // $("#jqg_table_list_1_"+ii).attr("disabled","disabled");
                    // $("#jqg_table_list_1_"+ii).css("display","none");
                
                }
                else{
                    if(parseInt(sessionStorage.getItem("roleId"))==2)
                    //审核通过不能修改
                    tab.find("td:last button").attr("disabled","disabled");
                }
           
            }

            if (sessionStorage.getItem("isParent") != "true") {
                $(".ui-row-ltr").each(function () {
                    if ($(this).find("td").eq(2).text() !== sessionStorage.getItem("coid")) {
                        $(this).hide();
                    }
                });
            }

        }
    });
}

//加载审核内容
window.queryExamine = function (programId) {

    $.ajax({
        type: 'POST',
        url: domain.testUrl + "/Threeinjection/programManagement/queryAuditorInfo",
        data: { sessionid: sessionStorage.getItem("sid"), coid: sessionStorage.getItem("coid"), "programId": programId },
        success: function (response) {
            response = JSON.parse(response);
            console.log("数据"+response)
           
            if (response!= "") {
                $("#numberNo").val(response[0].programId);
                $("#programNo").val(response[0].programNum);
                $("#programeName").val(response[0].programName);
                $("#examineMan").val(response[0].auditorName);
                $("#result").val(response[0].resultId);
                $("#reason").val(response[0].cause);
                
            } else {
                $(".close").click();
                    swal("提示","您好，管理员直接通过的节目没有详细信息可见！","info");
            }
        }
    });


};

$(function () {

    if (sessionStorage.getItem("isgroup") == "1") {

        $("label").eq(2).hide(); $("#devicetype").hide();
    }

    $("button").eq(0).click(function () {
        sizeval = 20;
        pageval = 1;
        $(".ui-pg-selbox").val(20);
        $("#table_list_1").setGridParam({rowNum:20});

        cxlist();
    });
    cxlist();


    $("#user_name").blur(function () {
        $("#myModal").find("span").eq(0).text("");
        if ($("#user_name").val().length == 0) {
            $("#myModal").find("span").eq(0).text("用户名不能为空");
            //  $("#user_name").focus();
            return;
        }
        if ($("#user_name").val().length > 0 && $("#user_name").val().length < 6) {
            $("#myModal").find("span").eq(0).text("长度只能在6-20个字符之间");
            //  $("#user_name").focus();  
            return;
        }
        if ($("#myModalLabel").text() == "新增") {
            domain.ajaxUrl({
                method: 'POST',
                url: domain.testUrl + "/Threeinjection/user/queryByUserName",
                data: { "userName": $("#user_name").val() },
                success: function (response) {

                    if (response == "\"no\"") {

                        $("#myModal").find("span").eq(0).text("用户名已经存在");
                        // $("#user_name").focus();
                        return;
                    }
                }

            });
        }


    });


    $("#mobile").blur(function () {
        $("#myModal").find("span").eq(1).text("");
        if ($("#mobile").val().length == 0) {

            $("#myModal").find("span").eq(1).text("手机号码不能为空");
            // $("#mobile").focus();
            return;
        }
        // if($("#mobile").val().substr(0,3)!=138&&$("#mobile").val().substr(0,3)!=189&&$("#mobile").val().substr(0,3)!=139&&$("#mobile").val().substr(0,3)!=158&&$("#mobile").val().substr(0,3)!=188&&$("#mobile").val().substr(0,3)!=157||$("#mobile").val().length!=11){

        //  $("#myModal").find("span").eq(1).text("手机号格式不正确");
        //$("#mobile").focus();
        // return;
        // }
        if (mobile != $("#mobile").val()) {
            domain.ajaxUrl({
                method: 'POST',
                url: domain.testUrl + "/Threeinjection/user/queryByUsermobile",
                data: { "mobile": $("#mobile").val() },
                success: function (response) {
                    if (response == "\"no\"") {
                        $("#myModal").find("span").eq(1).text("手机号码已经存在");
                        // $("#mobile").focus();  
                        return;
                    }
                }
            });
        }
    });
    $("#mail").blur(function () {
        $("#myModal").find("span").eq(2).text("");
        if ($("#mail").val().length > 0) {
            var myReg = /^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/;
            if (!myReg.test($("#mail").val())) {
                $("#myModal").find("span").eq(2).text("邮箱格式输入不正确");
                //  $("#mail").focus();
                return;
            }

        }
    });
    $("#company_name").blur(function () {
        console.log(123);
        $("#company_name").find("span").eq(3).text("");
        if ($("#company_name").val().length == 0) {
            $("#myModal").find("span").eq(3).text("");
            $("#myModal").find("span").eq(3).text("单位名称不能为空");
            //  $("#company_name").focus();
            return;
        }

    }); var table = "userinfo";
    $("#addtj").click(function () {
        var AZ = ["user_name", "account", "user_pwd", "company_id", "sex", "role_id", "enter_state", "email", "mobile"];//字段
        //var valAZ=["user_name","account","user_pwd","company_id","role_id","enter_state","email","mobile"];//字段

        //console.log(findval);
        $("#myModal").find("span").empty();
        //  return;
        //var dataadd={tableName:"userinfo","fieldlist":"user_name','account','user_pwd','company_id','sex','role_id','enter_state','email','mobile'",
        //  "stringvalueA":"'"+$("#user_name").val()+"',"+"'"+$("#user_name").val()+"',"+"'"+hex_md5("123456").toUpperCase()+"',"+"'"+$("#company_id").val()+"',"+"'"+$("#sex").val()+"',"+"'"+$("#jiaose").val()+"',"+"'"+$("#static").val()+"',"+"'"+$("#mail").val()+"',"+"'"+$("#mobile").val()+"'"}
        $("#user_name").blur(); $("#mobile").blur();
        $("#mail").blur(); $("#company_name").blur();
        //{“tableName”:”表名”, “fielded”:”user_id+”，” value”:”修改条件”}
        if ($("#myModal").find("span").text().length > 0) {
            return;
        }
        if ($("#myModalLabel").text() == "新增") {
            //var dataadd={tableName:"userinfo",fieldnameA:"user_name",fieldnameB:"account",fieldnameC:"user_pwd",fieldnameD:"company_id",fieldnameE:"role_id",fieldnameF:"enter_state",fieldnameG:"email",fieldnameH:"mobile",
            // stringvalueA:$("#user_name").val(),stringvalueB:$("#user_name").val(),stringvalueC:hex_md5("123456").toUpperCase(),stringvalueD:$("#company_id").val(),stringvalueE:$("#sex").val(),stringvalueF:$("#jiaose").val(),stringvalueL:$("#static").val(),stringvalueG:$("#mail").val(),stringvalueH:$("#mobile").val()}
            var val = [];//数据
            val.push($("#user_name").val());
            val.push($("#user_name").val());
            val.push(hex_md5("123456").toUpperCase());
            val.push($("#company_id").val());
            val.push($("#sex").val());
            val.push($("#jiaose").val());
            val.push($("#static").val());
            val.push($("#mail").val());
            val.push($("#mobile").val());

            var findval = domain.fieldthis(AZ, val, table);
            //var json=
            // {"tableName":"userinfo", "fielded":""，” valueid”:”修改条件”,”fieldnameA”:”需要修改的字段”，”stringvalueA”:”修改值” }
            domain.ajaxUrl({
                method: 'POST',
                url: domain.testUrl + "/Threeinjection/global/insert",
                data: findval,
                success: function (response) {

                    response = JSON.parse(response);
                    if (response.code == "200") {

                        $(".close").click();
                        pageval = 1;

                        cxlist();
                        swal("success!", "保存成功", "success");
                    }

                }
            });
        } else {

            var val2 = [];//数据
            val2.push($("#user_name").val());
            val2.push($("#user_name").val());
            val2.push(hex_md5("123456").toUpperCase());
            val2.push($("#company_id").val());
            val2.push($("#sex").val());
            // alert($("#jiaose").val());
            val2.push($("#jiaose").val());
            val2.push($("#static").val());
            val2.push($("#mail").val());
            val2.push($("#mobile").val());
            var findval = domain.fieldupdatethis(AZ, val2, "user_id", $("#user_id").val(), table);
            domain.ajaxUrl({
                method: 'POST',
                url: domain.testUrl + "/Threeinjection/global/update",
                data: findval,
                success: function (response) {

                    response = JSON.parse(response);
                    if (response.code == "200") {
                        pageval = 1;
                        cxlist();
                        $(".close").click();
                        swal("success!", "修改成功", "success");

                    }

                }
            });

        }
    });
});
Date.prototype.Format = function (fmt) {
    //author:wangweizhen
    var o = {
        "M+": this.getMonth() + 1,                 //月份   
        "d+": this.getDate(),                    //日
        "h+": this.getHours(),                   //小时   
        "m+": this.getMinutes(),                 //分   
        "s+": this.getSeconds(),                 //秒   
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度   
        "S": this.getMilliseconds()             //毫秒   
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

window.modify = function (programid, group_programid) {
    // if(sessionStorage.getItem("isgroup")=="0"){
    //     swal("OMG!","请选择卡组","error");
    //     return false;
    // }
    //$("#static").val("1");
    sessionStorage.setItem("programid", programid);
    sessionStorage.setItem("group_programid", parseInt(group_programid) + 1);


    parent.addTabs({ id: '100', title: '修改节目', close: true, url: '?#/page/Program/edit' });
    setTimeout(function () {

        var id = parent.$("#tabSuperior").find(".active").find("a").attr("href");
        var id2 = id.split('_');

        //  alert(parent.$("#if"+parent.$("#tabSuperior").find(".active").find("a").attr("href")).html());
        //$("#if"+parent.$("#tabSuperior").find(".active").find("a").attr("href")).reload();
        //parent.id="tab_100";
        //parent.closeTab("tab_100");

        parent.Addtabs.add({ 'id': id2[1], 'url': parent.$(id).children("iframe").attr("src") });


        //parent.$("#tab_tab_100").find("a").find(".glyphicon-remove").click();
        //parent.$("#iftab_100").attr("src","?#/page/Program/edit");



    }, 500);
    //parent.addTabs({id:'100',title: '修改节目',close: true,url: '?#/page/Program/edit'});
    // domain.jsonthis.userinfo=[json.rows[i].user_name];

};

$(function () {
    var programidval = "";

    $("#del").click(function () {
        programidval = "";
        var ids = $("#table_list_1").jqGrid("getGridParam", "selarrrow");

        //遍历访问这个集合
        $(ids).each(function (index, id) {
            //由id获得对应数据行
            var row = $("#table_list_1").jqGrid('getRowData', id);
            programidval += row.programid + ","
            //console.log("row.ID:"+row.programid);
        });
        programidval = programidval.substring(0, programidval.length - 1);
        // console.log(programid);
        if (programidval == "") {

            swal("OMG!", "请选择需要删除的节目", "error");
            return;
        }
        var msg = "确定删除节目吗？";
        if (confirm(msg) == true) {
            $.ajax({
                type: 'POST',
                url: domain.testUrl + "/Threeinjection/programManagement/deleteProgramInfo",
                data: { "programidList": programidval, sessionid: sessionStorage.getItem("sid") },

                success: function (response) {
                    response = JSON.parse(response);
                    if (response.code == "200") {

                        pageval = 1;
                        cxlist();
                        //刷新节目号:这个只能用来刷iframe,要找到iframe的id,tab就相当于iframe
                        parent.window.frames["iftab_101"].window.programlist();
                        swal("success!", "删除成功", "success");
                        

                    }

                }
            });
            return true;
        } else {
            return false;
        }
    });

    $("#delsb").click(function () {


        $("#sbfs").html("确定");



    });
    $("#fs").click(function () {


        $("#sbfs").html("发送");



    });



    $("#sbfs").click(function () {
        //    $("#sbfs").html("发送");
        if ($("#sbfs").html() == "发送") {
            if ($("#device_id").val() == "" && $("#companyid").val() == "") {

                swal("OMG!", "请选择设备或单位", "error");
                return false;

            } else {

                var rowData = $('#table_list_1').jqGrid('getGridParam', 'selarrrow');




                var programid = ""; var type = "";
                if (rowData.length) {
                    for (var i = 0; i < rowData.length; i++) {
                        programid += $('#table_list_1').jqGrid('getCell', rowData[i], 'programid') + ",";//name是colModel中的一属性

                        //if($('#table_list_1').jqGrid('getCell',rowData[i],'type')=="""")

                        var type1 = $('#table_list_1').jqGrid('getCell', rowData[i], 'devicetype');

                        if (type1 == "单色") {

                            type = 0;
                        }
                        if (type1 == "双色") {

                            type = 0;
                        }

                        if (type1 == "全彩") {

                            type = 1;
                        }




                        if (type1 == "安卓") {

                            type = 2;
                        }
                    }
                }
                programid = programid.substring(0, programid.length - 1);
                if (programid == "") {
                    swal("OMG!", "请选择节目", "error");
                    return false;

                }
              
                var ids = $("#table_list_1").jqGrid("getGridParam", "selarrrow");
                var ro = "";
                var flag = true;
                //遍历访问这个集合
                $(ids).each(function (index, id) {

                    ro = $("#table_list_1 #" + id + " .permissions").val();
                    if (parseInt(ro) != 1) {
                        flag = false;
                        swal("OMG!", "节目未审核不能发送节目，请联系管理员或者审核员进行节目审核！", "error");
                        return false;

                    }
                });
                //未审核跳出
                if (flag == false) {
                    return false;
                }
            
                var coidval = $("#companyid").val();
                if (coidval.indexOf(',') != -1) {
                    coidval = coidval.split(',')[0];
                }


                //if(programid.indexOf("3")!=-1){

                // swal("OMG!", "安卓节目,目前不能发送", "error");
                //return false;
                // }
                // type = type.substring(0, type.length-1);
                // alert(type);
                //return;


                var timer = setInterval(function ()   //开启循环：每秒出现一次提示框
                {
                    $("body").mLoading("show");
                }, 500);


                $.ajax({
                    type: 'POST',
                    url: domain.testUrl + "/Threeinjection/programManagement/sendProgramInfoToDeivce",
                    data: { sessionid: sessionStorage.getItem("sid"), "programid": programid, type: $("#type_val").val(), 
                    "devicenumber": $("#device_id").val(),companyid: coidval },
                    sessionid: sessionStorage.getItem("sid"),
                    // timeout: 8000,//超时设置
                    // async:true,
                    success: function (response) {
                        response = JSON.parse(response);
                        if (response.code == "200") {
                            clearInterval(timer);
                            // $(".mloading-mask").hide();
                            $("body").mLoading("hide");
                            swal("success!", "节目提交成功，如需看到发送进度，请关注发送记录页面", "success");
                            $(".close").click();
                            sizeval = 20;
                            pageval = 1;
                            cxlist();
                        } else {

                            clearInterval(timer);
                            // $(".mloading-mask").hide();
                            $("body").mLoading("hide");
                            swal("OMG!", "节目提交失败", "error");


                        }
                    }, error: function (response, ajaxOptions, thrownError) {

                        $(".mloading-mask").hide();
                        swal("OMG!", "节目提交失败", "error");
                    },
                    complete: function (XMLHttpRequest, status) {

                        if (status == 'timeout') {
                            $(".mloading-mask").hide();
                            // swal("OMG!", "发送失败", "error");

                        }
                    }
                });
            }
        } else {

            if ($("#device_id").val() == "" && $("#companyid").val() == "") {

                swal("OMG!", "请选择设备或单位", "error");
                return false;

            } else {

                var rowData = $('#table_list_1').jqGrid('getGridParam', 'selarrrow');

                if (rowData == "") {
                    swal("OMG!", "请选择节目", "error");
                    return false;
        
                }

                var ids = $("#table_list_1").jqGrid("getGridParam", "selarrrow");
                var ro = "";
                var flag = true;
                //遍历访问这个集合
                $(ids).each(function (index, id) {

                    ro = $("#table_list_1 #" + id + " .permissions").val();
                    if (parseInt(ro) != 1) {
                        flag = false;
                        swal("OMG!", "抱歉，节目未通过不能下架", "error");
                        return false;

                    }
                });
                //未审核跳出
                if (flag == false) {
                    return false;
                }


                var programid =new Array(); var type = "";
                if (rowData.length) {
                    for (var i = 0; i < rowData.length; i++) {
                        programid[i]=$('#table_list_1').jqGrid('getCell', rowData[i], 'group_programid');//name是colModel中的一属性

                        //if($('#table_list_1').jqGrid('getCell',rowData[i],'type')=="""")

                        var type1 = $('#table_list_1').jqGrid('getCell', rowData[i], 'devicetype');

                        if (type1 == "单色") {

                            type = 0;
                        }
                        if (type1 == "双色") {

                            type = 1;
                        }

                        if (type1 == "全彩") {

                            type = 2;
                        }




                        if (type1 == "安卓") {

                            type = 3;
                        }
                    
               
                
                if (programid == "") {
                    swal("OMG!", "请选择节目", "error");
                    return false;

                }
                //if(programid.indexOf("3")!=-1){

                // swal("OMG!", "安卓节目,目前不能发送", "error");
                //return false;
                // }
                // type = type.substring(0, type.length-1);
                // alert(type);
                //return;
                //接口 /DeviceManagement/deviceCommand   参数  cmd 命令码47  devicenumber设备号，多个用逗号分隔，deviceType设备类型，programGroupId节目id，companyId 公司id
                $("body").mLoading();
                var coidval = $("#companyid").val();
                if (coidval.indexOf(',') != -1) {
                    coidval = coidval.split(',')[0];
                }
                $.ajax({
                    type: 'POST',
                    url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
                    data: { cmd: 47, sessionid: sessionStorage.getItem("sid"), "programGroupId": parseInt(programid[i])-1, deviceType: type, "devicenumber": $("#device_id").val(), companyId: coidval },
                    sessionid: sessionStorage.getItem("sid"),
                    // timeout: 8000,//超时设置

                    success: function (response) {
                        response = JSON.parse(response);
                        if (response.code == "200") {


                            $(".mloading-mask").hide();

                            swal("success!", "下架成功", "success");
                            $(".close").click();
                            sizeval = 20;
                            pageval = 1;
                            cxlist();
                        } else {

                            $(".mloading-mask").hide();
                            swal("OMG!", "下架失败", "error");


                        }
                    }, error: function (response, ajaxOptions, thrownError) {

                        $(".mloading-mask").hide();
                        swal("OMG!", "下架失败", "error");
                    },
                    complete: function (XMLHttpRequest, status) {

                        if (status == 'timeout') {
                            $(".mloading-mask").hide();
                            // swal("OMG!", "发送失败", "error");

                        }
                    }
                });
            }
        }
        }
    }
    });

   


    $("#typecplay").change(function(){
        console.log("值："+$(this).val())
        if($(this).val()=="0"){
            $(".dispySele:eq(0)").show();
            $(".dispySele:eq(1)").hide();
            console.log("没进来")
        }else{
            $(".dispySele:eq(0)").hide();
            $(".dispySele:eq(1)").show();
            console.log("有")
         }
    });

    //加载生成时间控件的方法，调用time.js里的
		showTimer('startTime',1);
        showTimer('endTime',1);
        // for(var i=1;i=1;i++)
        //  $("#startTime").find("input").removeAttr("disabled");
        //  $("#endTime").find("input").removeAttr("disabled");

 });


//跳转到发送状态中
window.state = function (programid, devicetype) {

    sessionStorage.setItem("programid", programid);
    sessionStorage.setItem("deviceType", devicetype);
    //parent.addTabs({id:'104',title: '节目状态',close: true,url: '?#/page/Program/liststate'});
    
   $("#state").click();
   window.frames["iframescr"].window.cxlist();
    //   setTimeout(function(){
    // document.getElementById('iframescr').contentWindow.location.reload(true);
    //},500);

};



